import request from "@/utils/request";

// 基础销售属性所有属性的类型
export interface baseSaleAttrItemType {
  id: number;
  name: string;
}

// 基础销售属性列表的类型
export type baseSaleAttrListType = baseSaleAttrItemType[];

// 1.0 获取基础销售属性列表
export const reqBaseSaleAttrList = () => {
  return request.get<null,baseSaleAttrListType>(`/admin/product/baseSaleAttrList`);
};

// 2.0 删除某一个spu
export const reqDeleteSpu = (spuId: number) => {
  return request.delete<null, null>(`/admin/product/deleteSpu/${spuId}`);
};

// 单个spu的图片列表所有属性类型
export interface spuImgItemType {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number; //当前图片所在的spu的id
  name?: string;
  url?: string;
  response?: any;
  isDefault?: string;// 图片排他
}

// 单个spu的图片列表类型
export type spuImgListType = spuImgItemType[];

// 销售属性值 列表的所有属性的类型
export interface saleAttrValueItemType {
  baseSaleAttrId: number; 
  id?: number;
  isChecked: string; 
  saleAttrName: string; 
  saleAttrValueName: string; 
  spuId?: number; 
}

// 销售属性值 列表的类型
export type saleAttrValueListType = saleAttrValueItemType[];

// 销售属性 列表所有属性的类型
export interface saleAttrItemType {
  baseSaleAttrId: number;
  id?: number;
  saleAttrName: string;
  spuId?: number;
  spuSaleAttrValueList: saleAttrValueListType;
  isEdit?:boolean;
  selectData?: string;
}

//11.销售属性 列表的类型
export type saleAttrListType = saleAttrItemType[];

// // 新增 or 修改 spu 参数
// export interface spuInfoType {
//   category3Id: number;
//   description: string;
//   id?: number;
//   spuImageList: spuImgListType; 
//   spuName: string;
//   spuSaleAttrList: saleAttrListType; //当前spu的销售属性列表; 
//   tmId: number;
// }

// 3.0 新增spu
export const reqAddSpu = (spuInfo: spuItemType) => {
  return request.post<null, null>(`/admin/product/saveSpuInfo`, spuInfo);
};

// 4.0 修改spu
export const reqUpdateSpu = (spuInfo: spuItemType) => {
  return request.post<null, null>(`/admin/product/updateSpuInfo`, spuInfo);
};

// 5.0 根据spuId获取自己的销售属性列表
export const reqSaleAttrSelf = (spuId: number) => {
  return request.get<null, saleAttrListType>(
    `/admin/product/spuSaleAttrList/${spuId}`
  );
};

// 6.0 根据spuId获取ImgList列表
export const reqSpuImageList = (spuId: number) => {
  return request.get<null, spuImgListType>(
    `/admin/product/spuImageList/${spuId}`
  );
};

// 单个spu对象的类型
export interface spuItemType {
  id?: number;
  spuName: string;
  description: string;
  category3Id: number;
  tmId: number;
  spuSaleAttrList: null | saleAttrListType;
  spuImageList: null | spuImgListType;
}

// spu分页列表的数组类型
export type spuListType = spuItemType[];

// spu分页列表的返回值类型
export interface spuListReturnType {
  records: spuListType;
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
}

// 7.0 获取spu的分页列表
export const reqSpuList = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<null, spuListReturnType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );
};